// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        traceUser: true,
      })
    }

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  getLocation: function() {
    const that = this;
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        that.globalData.userLocation = {
          latitude: res.latitude,
          longitude: res.longitude
        };
      },
      fail() {
        // 默认设置为北京
        that.globalData.userLocation = {
          latitude: 39.9042,
          longitude: 116.4074
        };
      }
    });
  },
  globalData: {
    userInfo: null,
    weatherApiKey: '6e4aa9b855be46bb89829d825d1720b5', // 替换为您的和风天气API密钥
    user: ''
  }
})
